package edu.hitsz.shoot;

import edu.hitsz.aircraft.AbstractAircraft;
import edu.hitsz.aircraft.HeroAircraft;
import edu.hitsz.aircraft.MobEnemy;
import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.bullet.EnemyBullet;
import edu.hitsz.bullet.HeroBullet;

import java.util.LinkedList;
import java.util.List;

public class DiffuseShoot implements ShootStrategy{
    private AbstractAircraft aircraft;
    private int direction;
    private int shootNum = 3;
    private int power = 30;
    public DiffuseShoot(AbstractAircraft _aircraft, int _direction)
    {
        this.aircraft = _aircraft;
        direction = _direction;
    }

    @Override
    public List<BaseBullet> shoot() {
        List<BaseBullet> res = new LinkedList<>();
        int x = this.aircraft.getLocationX();
        int y = this.aircraft.getLocationY() + direction*2;
        int speedX = -3;
        int speedY = direction*10;
        BaseBullet bullet;
        for(int i=0; i<shootNum; i++){
            // 子弹发射位置相对飞机位置向前偏移
            // 多个子弹横向分散
            if(this.aircraft instanceof MobEnemy)
                bullet = new EnemyBullet(x + (i*2 - shootNum + 1)*10, y, speedX + i*3, speedY, power);
            else
                bullet = new HeroBullet(x + (i*2 - shootNum + 1)*10, y, speedX + i*3, speedY, power);
            res.add(bullet);
        }

        return res;
    }

}
